package remotecontrolcase;

import remotecontrolcase.command.Command;
import remotecontrolcase.command.NoCommand;

/**
 * description:
 *  遥控器
 * @author yuanmenglv on 2019/11/30
 */
public class RemoteControll {
    private Command[] onCommand;
    private Command[] offCommand;

    public RemoteControll(){
        this.onCommand = new Command[7];
        this.offCommand = new Command[7];
        NoCommand noCommand = new NoCommand();
        for ( int i = 0; i < onCommand.length; i++ ) {
            onCommand[i] = noCommand;
            offCommand[i] = noCommand;
        }
    }

    /**
     * 给遥控器指定位置设置命令
     * @param slot
     * @param onCommand
     * @param offCommand
     */
    public void setCommand(int slot, Command onCommand, Command offCommand){
        this.onCommand[slot] = onCommand;
        this.offCommand[slot] = offCommand;
    }

    /**
     *  按下遥控器指定位置按钮
     * @param slot  遥控器位置
     */
    public void buttonWasPushed(int slot){
        this.onCommand[slot].execute();
    }

    /**
     * 按回遥控器指定位置按钮
     * @param slot
     */
    public void buttonWasUnpushed(int slot){
        this.offCommand[slot].execute();
    }

}
